<?php

namespace Xrfg\Core\Trading\Spot\Models;

use Illuminate\Database\Eloquent\Model;
use Xrfg\Core\User\Models\User;

/**
 * Xrfg\Core\Trading\Spot\Models\Trade.
 *
 * @property int                             $id
 * @property string                          $symbol        交易对符号
 * @property string                          $side          买入/卖出
 * @property int                             $coin_id       币种ID
 * @property int                             $market_id     交易区ID
 * @property int                             $buy_user_id   买家ID
 * @property int                             $sell_user_id  卖家ID
 * @property int                             $buy_order_id  买订单ID
 * @property int                             $sell_order_id 卖订单ID
 * @property float                           $price         成交价格
 * @property float                           $number        成交数量
 * @property float                           $buy_fee       买方手续费
 * @property float                           $sell_fee      卖方手续费
 * @property \Illuminate\Support\Carbon|null $created_at    成交时间
 * @property \Xrfg\Core\User\Models\User     $seller
 * @property \Xrfg\Core\User\Models\User     $user
 *
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade query()
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereBuyFee($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereBuyOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereBuyUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereCoinId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereMarketId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade wherePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereSellFee($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereSellOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereSellUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereSide($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Xrfg\Core\Trading\Spot\Models\Trade whereSymbol($value)
 * @mixin \Eloquent
 */
class Trade extends Model
{
    protected $table = 'trading_spot_trades';

    /**
     * @var int 类编码
     */
    const CLASS_ID = 5;
    /**
     * @var int 操作编码：币币买入成交-入账户
     */
    const OP_BUY_DEAL_IN = 1;
    /**
     * @var int 操作编码：币币买入成交-出账户
     */
    const OP_BUY_DEAL_OUT = 2;
    /**
     * @var int 操作编码：币币卖出成交-入账户
     */
    const OP_SELL_DEAL_IN = 3;
    /**
     * @var int 操作编码：币币卖出成交-出账户
     */
    const OP_SELL_DEAL_OUT = 4;
    /**
     * @var int 操作编码：币币交易差价返还
     */
    const OP_DEAL_SPREAD = 5;

    public $timestamps = false;

    protected $dates = [
        'created_at',
    ];

    // 买入
    const SIDE_BUY = 'BUY';
    // 卖出
    const SIDE_SELL = 'SELL';

    public function user()
    {
        return $this->belongsTo(User::class, 'buy_user_id');
    }

    public function seller()
    {
        return  $this->belongsTo(User::class, 'sell_user_id');
    }
}
